﻿using Hotel.IDAL;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Hotel.DAL
{
    public class BaseDAL<T> : IBaseDAL<T> where T : class
    {
        MyDbContext db;
        public BaseDAL(MyDbContext db)
        {
            this.db = db;
        }
        /// <summary>
        /// 根据条件做查询
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<T> GetValue(Expression<Func<T, bool>> exp)
        {
            return await db.Set<T>().Where(exp).FirstOrDefaultAsync();
        }
    }
}
